// import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLRecordDataType.h"
#include "statement/SQLColumnDefinition.h"
#include "../visitor/SQLASTVisitor.h"
#include "../../utils/listTran.h"

SQLRecordDataType::SQLRecordDataType()
{
  columns = std::make_shared<std::list<SQLColumnDefinition_ptr>>();
}
SQLColumnDefinition_list_ptr SQLRecordDataType::getColumns()
{
  return columns;
}

void SQLRecordDataType::addColumn(SQLColumnDefinition_ptr column)
{
  column->setParent(SharedObject(SQLRecordDataType));
  this->columns->push_back(column);
}

SQLObject_ptr SQLRecordDataType::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLRecordDataType>(new SQLRecordDataType());
  std::shared_ptr<SQLRecordDataType> x = std::dynamic_pointer_cast<SQLRecordDataType>(clone_tmp);
  // SQLRecordDataType x = new SQLRecordDataType();
  cloneTo(x);

  for (SQLColumnDefinition_ptr c : *columns)
  {
    SQLColumnDefinition_ptr c2 = std::dynamic_pointer_cast<SQLColumnDefinition>(c->clone());
    c2->setParent(x);
    x->columns->push_back(c2);
  }

  return x;
}

void SQLRecordDataType::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLRecordDataType)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLColumnDefinition, SQLObject>(this->columns);
    acceptChild(visitor, tmp1);
  }

  visitor->endVisit(SharedObject(SQLRecordDataType));
}
